Skip to content

fix: TypeError - requests.Session.request() got an unexpected keyword argument 'user_agent_overwrite'#45653

Merged
simorenoh merged 3 commits intomainfrom
users/dibahl/user-agent-fix
Mar 16, 2026
Merged

fix: TypeError - requests.Session.request() got an unexpected keyword argument 'user_agent_overwrite'#45653
simorenoh merged 3 commits intomainfrom
users/dibahl/user-agent-fix

Conversation

@dibahlfi
Copy link
Member

This PR fixes a regression introduced with v4.15.0b1 release where the user_agent_overwrite kwarg was not popped from kwargs after being consumed by CosmosUserAgentPolicy.init(). This caused the kwarg to leak through _GetDatabaseAccount(**kwargs) into the HTTP transport layer, resulting in:
TypeError: requests.Session.request() got an unexpected keyword argument 'user_agent_overwrite'

@dibahlfi dibahlfi requested a review from a team as a code owner March 11, 2026 23:34
Copilot AI review requested due to automatic review settings March 11, 2026 23:34
@dibahlfi
Copy link
Member Author

/azp run python - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression in azure-cosmos (introduced in v4.15.0b1) where user_agent_overwrite was unintentionally left in the kwargs passed down into the transport layer, causing requests.Session.request() to raise a TypeError.

Changes:

  • Pop user_agent_overwrite from client-connection kwargs in both sync and async Cosmos client connection implementations to prevent it from leaking into lower layers.
  • Add sync + async regression tests that exercise combinations of user_agent, user_agent_suffix, and user_agent_overwrite to ensure no transport-level kwarg leakage.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

File Description
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py Removes user_agent_overwrite from kwargs after it has been consumed for policy setup (sync path).
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py Removes user_agent_overwrite from kwargs after it has been consumed for policy setup (async path).
sdk/cosmos/azure-cosmos/tests/test_user_agent.py Adds a sync regression test to validate user_agent_overwrite doesn’t leak into transport kwargs.
sdk/cosmos/azure-cosmos/tests/test_user_agent_async.py Adds an async regression test to validate user_agent_overwrite doesn’t leak into transport kwargs.

Copy link
Member

@tvaron3 tvaron3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@simorenoh simorenoh merged commit 30f1ea3 into main Mar 16, 2026
22 checks passed
@simorenoh simorenoh deleted the users/dibahl/user-agent-fix branch March 16, 2026 18:32
rohitsinghal4u pushed a commit that referenced this pull request Mar 16, 2026
… argument 'user_agent_overwrite' (#45653)

* fix - TypeError: Session.request() got an unexpected word argument 'user_agent_overwrite

* fix - updating changelog

---------

Co-authored-by: Simon Moreno <30335873+simorenoh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants